<%--
  Created by IntelliJ IDEA.
  User: bbb
  Date: 2025/3/21
  Time: 15:37
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>登录</title>
    <!-- Bootstrap -->
    <%--    <link href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css" rel="stylesheet">--%>
    <style>
        body {
            background-color: #f4f4f9;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            background-image: url('${pageContext.request.contextPath}/images/login.png');
            background-size: cover;
            background-position: center;
        }
        .login-container {
            background-color: rgba(255, 255, 255, 0.9);
            padding: 40px;
            border-radius: 10px;
            box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
            width: 350px;
            text-align: center;
        }
        .login-container h2 {
            margin-bottom: 30px;
            color: #333;
        }
        .form-group label {
            font-weight: bold;
            text-align: left;
            display: block;
            margin-bottom: 5px;
            color: #555;
        }
        .form-group input {
            border-radius: 5px;
            border: 1px solid #ccc;
            padding: 10px;
            width: 100%;
            box-sizing: border-box;
        }
        .form-group input:focus {
            border-color: #007bff;
            outline: none;
        }
        .btn-login {
            width: 100%;
            background-color: #007bff;
            border-color: #007bff;
            padding: 10px;
            font-size: 16px;
            border-radius: 5px;
        }
        .btn-login:hover {
            background-color: #0056b3;
            border-color: #0056b3;
        }
        .register-link {
            margin-top: 20px;
            color: #007bff;
            text-decoration: none;
        }
        .register-link:hover {
            text-decoration: underline;
        }
        .error-message {
            color: red;
            font-size: 14px;
            margin-top: 5px;
        }
    </style>
</head>
<body>

<div class="login-container">
    <h2>登录</h2>
    <form action="${pageContext.request.contextPath}/user/login" method="post" onsubmit="return validateForm()">
        <div class="form-group">
            <label for="username">用户名</label>
            <input type="text" class="form-control" id="username" name="u_name" required>
            <div id="usernameError" class="error-message"></div>
        </div>
        <div class="form-group">
            <label for="password">密码</label>
            <input type="password" class="form-control" id="password" name="u_pass" required>
            <div id="passwordError" class="error-message"></div>
        </div>
        <button type="submit" class="btn btn-primary btn-login">登录</button>
    </form>
    <a href="${pageContext.request.contextPath}/register.jsp" class="register-link">还没有账号？立即注册</a>
</div>

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<%--<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js"></script>--%>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<%--<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.min.js"></script>--%>

<script>
    function validateForm() {
        let username = document.getElementById("username").value;
        let password = document.getElementById("password").value;
        let isValid = true;

        // 清除之前的错误信息
        document.getElementById("usernameError").textContent = "";
        document.getElementById("passwordError").textContent = "";

        // 验证用户名长度
        if (username.length < 3 || username.length > 10) {
            document.getElementById("usernameError").textContent = "用户名长度必须在3到10个字符之间";
            isValid = false;
        }

        // 验证密码长度
        if (password.length < 4 || password.length > 15) {
            document.getElementById("passwordError").textContent = "密码长度必须在4到15个字符之间";
            isValid = false;
        }

        return isValid;
    }
</script>

</body>
</html>
